﻿using DotsGame;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Unity.Entities;
using Unity.Transforms;

[UpdateAfter(typeof(system1_game))]
partial struct system2_count : ISystem
{
    EntityQuery queryUnit;
    EntityQuery queryEffect;
    void OnCreate(ref SystemState state)
    {
        //本系统的启动条件
        state.RequireForUpdate<dotscomp_StartTag>();

        queryUnit = state.GetEntityQuery(typeof(comp_BattleUnit),typeof(comp_BattleUnitTag));

        queryEffect = state.GetEntityQuery(typeof(comp_autodestory_effect));
    }
    void OnUpdate(ref SystemState state)
    {
        //统计各阵营单位数量
        var data = CommonData.Instance;

      
        data.Data.EffectCount = queryEffect.CalculateEntityCount();
        {
            queryUnit.ResetFilter();

            queryUnit.AddSharedComponentFilter(new comp_BattleUnitTag()
            {
                maintarget = false,
                campid = 0,
            });
            data.Data.campA.UnitCount = queryUnit.CalculateEntityCount();

            queryUnit.ResetFilter();

            queryUnit.AddSharedComponentFilter(new comp_BattleUnitTag()
            {
                maintarget = true,
                campid = 0,
            });
            data.Data.campA.MainUnitCount = queryUnit.CalculateEntityCount();

            queryUnit.ResetFilter();
            queryUnit.AddSharedComponentFilter(new comp_BattleUnitTag()
            {
                maintarget = false,
                campid =1,
            });
            data.Data.campB.UnitCount = queryUnit.CalculateEntityCount();

            queryUnit.ResetFilter();
            queryUnit.AddSharedComponentFilter(new comp_BattleUnitTag()
            {
                maintarget = true,
                campid = 1,
            });
            data.Data.campB.MainUnitCount = queryUnit.CalculateEntityCount();
        }
    }
    void OnDestroy(ref SystemState state) { }
}